package servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ServletDemo4")
public class ServletDemo4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String s ="这个世界被我毁灭！";
        //设置缓存  1小时的缓存
        resp.setDateHeader("Expires",System.currentTimeMillis()+1*60*60*1000);
        //设置格式
        resp.setContentType("text/html;charset=UTF-8");
        //写数据
        PrintWriter writer = resp.getWriter();
        writer.write(s);
        System.out.println("执行了---------------");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

